home *** CD-ROM | disk | FTP | other *** search
/ CICA 1995 August / CICA - The Ultimate Collection of Shareware for Windows (Disc 2) (August 1995).iso / disc2 / patches / symantec / rtlinc.exe / EXITSTAT.H < prev    next >
C/C++ Source or Header  |  1993-05-18  |  1KB  |  57 lines

  1. /*    exitstate.h
  2.  *    pushs and pops exit frame, so exit & atexit return points can
  3.  *    be controlled. Useful in Windows and for turning a standalone
  4.  *    program into a subroutine. A maximum of 16 states can be saved.
  5.  *
  6.  *    Written by: G. Eric Engstrom
  7.  */
  8.  
  9. #ifndef __EXITSTAT_H
  10. #define __EXITSTAT_H
  11. #ifdef __cplusplus
  12. extern "C"
  13.   {
  14. #endif
  15.  
  16. #include    <setjmp.h>
  17.  
  18. #ifndef __STDC__
  19. int __cdecl exit_PUSHSTATE(void);
  20. int __cdecl exit_popstate(void);
  21. #else
  22. int exit_PUSHSTATE(void);
  23. int exit_popstate(void);
  24. #endif
  25.  
  26. extern jmp_buf _exit_state;
  27.  
  28. #define exit_pushstate(RESULT) \
  29. ((exit_PUSHSTATE()!=0)?RESULT=2:\
  30. (((RESULT=setjmp(_exit_state))!=0)?exit_popstate(),RESULT:RESULT))
  31.  
  32. /* example usage:
  33.  * int  a;
  34.  *    if (exit_pushstate(a) == 0)
  35.  *      {
  36.  *      sub();            // your functions that may call exit
  37.  *      exit_popstate();        // only call if exit_pushstate returns 0
  38.  *      }
  39.  *    else
  40.  *      {
  41.  *      --a;                // a == return value now,
  42.  *      }                // exit_pushstate always returns exit value + 1
  43.  *
  44.  *  ...
  45.  *
  46.  * void sub()
  47.  * {
  48.  *    ...
  49.  *    exit(2);                // rather than exit program,
  50.  * }                    // this will 'call up' to exit_pushstate
  51.  *                    // and then drop down to the else case with a == 3
  52.  */
  53. #ifdef __cplusplus
  54.   }
  55. #endif
  56. #endif
  57.